<template>
  <div>
    <form>
      <h1>添加新的pizza</h1>
      <div>
        <label>品种</label>
        <input type="text" v-model="newShop.pinZhong" />
      </div>
      <div>
        <label>描述</label>
        <textarea cols="30" rows="10" v-model="newShop.miaoSu"></textarea>
      </div>
      <div>
        <h2>选项1</h2>
        <label for>尺寸</label>
        <input type="text" v-model="newShop.size1" />
        <label for>价格</label>
        <input type="text" v-model="newShop.price1" />
      </div>
      <div>
        <h2>选项2</h2>
        <label for>尺寸</label>
        <input type="text" v-model="newShop.size2" />
        <label for>价格</label>
        <input type="text" v-model="newShop.price2" />
      </div>
      <button type="submit" @click="onSubmit">添加</button>
    </form>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      newShop: {}
    };
  },
  methods: {
    onSubmit() {
      //   console.log(123123);
      let data = {
        name: this.newShop.pinZhong,
        miaoSu: this.newShop.miaoSu,
        options: [
          {
            size1: this.newShop.size1,
            price1: this.newShop.price1
          },
          {
            size2: this.newShop.size2,
            price2: this.newShop.price2
          }
        ]
      };
      axios.post("/menu.json", data).then(res =>
        //   console.log(res)
        this.$router.push("/login")
      );
    }
  }
};
</script>